<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page contentType="text/html;charset=UTF-8"%>
<%@taglib uri="/struts-tags" prefix="s"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="<%=basePath%>">
		<link href="themes/css/ui.common.css" rel="stylesheet" type="text/css" />
		<link href="themes/css/ui.child.css" rel="stylesheet" type="text/css" />
		<link href="themes/css/ui.tips.css" rel="stylesheet" type="text/css" />
		<link href="style/jquery_ui/jquery-ui-1.8.custom.css" rel="stylesheet"
			type="text/css" />
		<link id="skin_css" rel="stylesheet" type="text/css"
			href="themes/css/ui.c.blue.css"></link>
		<link rel="stylesheet" href="themes/default/pagination.css"
			type="text/css"></link>
		<link rel="stylesheet" href="themes/css/ui.validation.css" type="text/css"></link>
		<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
		<script src="Scripts/jquery-ui-1.8.custom.min.js"
			type="text/javascript"></script>
		<script src="Scripts/ui.tips.js" type="text/javascript"></script>
		<script src="Scripts/ui.default.js " type="text/javascript"
			charset="UTF-8"></script>
		<script src="Scripts/ui.admincp.js" type="text/javascript"
			charset="UTF-8"></script>
		<script type="text/javascript" src="Scripts/jquery.json-2.2.min.js"></script>
		<STYLE type="text/css">
		.editorArea {
			display: none;
		}
		</STYLE>
		<script type="text/javascript" src="Scripts/ui.dialogFormHelper.js"></script>
		<script type="text/javascript" src="Scripts/ui.validation.js"></script>
		<SCRIPT type="text/javascript">
			$(function(){
				$("#dialog").dialog("destroy"); 
				$("#dialog-form").dialog({
				autoOpen: false,
				height: 300,
				width: 550,
				modal: true,
				 
				close: function() {
					//allFields.val('').removeClass('ui-state-error');
				}
				});
				
				$('#addGoodButton').click(function() {   
					$("#dialog-form").dialog({'title':"新增物品信息"});
					clearInputControlValue("#dialog-form");
					$.fn.validatingForm.BlurErrorTips("#form");
				    $('#dialog-form').dialog('open'); 
				});
	            //registeTabToggle("#addPostCategoryButton", "#cancelAddPostCategoryButton");
	            //注册功能按钮事件..
	            registeRowFuncButton();
				setValidate();
			    });
			    
			   function setValidate(){
    	 		$("#form").validatingForm({
        		submitButtonId:"#btnSubmit",
        	  	clearErrorsOnFocus:true,
        	 	validateOnBlur:true,
        	 	success:submit
        		});
        		}
				//单击编辑按钮的时候,进行编辑, 
				//该模块中,需要在弹出层中编辑,因此可以在这里对弹出层上的表单控件进行赋值,
				//之后调用 最后一行代码显示弹出层..
				//如果不需要在弹出层进行编辑,可以直接在编辑按钮的 href 里面执行action 跳转..etc..
				//
				
				// 参数 e 包含两个属性:
				//			data ---> 所单击行的数据(一个数组)
				//			entityId ---> 对应 对象的 ID
				function toEditHandler(e)
				{ 
				    var columns = e.data;
					$("#dialog-form").dialog({'title':"修改物品信息"});
					$("#txt_goodNo").val($(columns[2]).text());
					$("#txt_goodName").val($(columns[3]).text());
					$("#txt_goodNum").val($(columns[4]).text());
					$("#goodId").val(e.entityId);
					// $("#txt_goodNum").attr("disabled", true);
					$.fn.validatingForm.BlurErrorTips("#form");
					$('#dialog-form').dialog('open'); 
				}
				
				function toDeleteHandler(e)
				{
				  
			   	 	var postId = e.entityId;
			     	location="goodInfo!delete.action?goodId="+postId+"&currpage="+$("#currentPage").val();
				}
				
				function checkAll(str)
				{
 					var items = document.getElementsByName(str);//获取所有复选框
					var totalNum = items.length;//获取复选框的个数
 					for (var i=0; i<totalNum; i++)
 					items[i].checked = window.event.srcElement.checked;//通过单击的按钮判断是选中还是未选
				}
				
				function deleteAll(str)
				{	
					var isTo = checkDeleteAll("物品信息记录");

					if(isTo==false)
  					return ;
 					var items = document.getElementsByName(str);//获取所有复选框
					var totalNum = items.length;//获取复选框的个数
					var delStr = "";
					for (var i=0; i<totalNum; i++){
 						if(items[i].checked == true){
							delStr += items[i].value + ","; 
						}
					}
					delStr = delStr.substring(0, delStr.length -1);
					location.href="goodInfo!delete.action?goodIds="+delStr+"&currpage="+$("#currentPage").val();
				}
				
				function submit(){			
					$.post(
					"goodInfo!addOrModify.action",{"goodId": $.trim($("#goodId").val()),"goodNo": $.trim($("#txt_goodNo").val()),"goodName":$.trim($("#txt_goodName").val()),"goodNum":$.trim($("#txt_goodNum").val())},
					function(data){
						if(data == "1"){
							alert("提示:操作成功！");
							location="goodInfo!toQuery.action?currpage="+$("#currentPage").val();
						}
						if(data == "-1"){
							alert("错误:操作失败！");
							return;
						}
					});
				}
			</script>
			<SCRIPT type="text/javascript">
			var searching = false;
				$(function(){
					$("#link_page_prev,#link_page_next").click(function(){
			    		var currentPage = $(this).attr("currentPage");
			    	 
			    		goToPage(currentPage);
			    	}); 
			    	
			    	$("#searchButton").click(function(){
						searching=true;
			    		goToPage(1);
			    	});
			    	
			    	initSearch();
			    	 
				});
				
				function initSearch()
				{
				    $("#search_txt_goodName").val();
				    $("#search_drl_states").val();
				}
			 
				function goToPage(currentPage)
				{
				    var goodName =$("#search_txt_goodName").val();
				    var states = $("#search_drl_states").val();
				     
					location.href = "goodInfo!toQuery.action?currpage="+currentPage+"&goodName="+goodName+"&states="+states;
				}
				</SCRIPT>
	</head>
	<body>
		<div class="PageChild_Title">
			<img src=" themes/images/default/icons/archives.png"
				class="PageChild_Tbtnpic" />
			<span class="PageChild_separate"></span>
			<span class="PageChild_TbtnText"><h2>
					物品信息管理
				</h2>
			</span>
			<span class="PageChild_separate"></span>
			<div id="marker" class="red-tips">
			</div>
			<div class="clear">
			</div>
		</div>
		<div class="PageChild_Where">
			<table style="height: 60px;" border="0" cellpadding="0"
				cellspacing="0">
				<tr>
					<td class="mtd">
							&nbsp;物品名称:<input id="search_txt_goodName" name="goodName" type="text"  class="control-width-100 input-control" value="${goodName}"/>
							&nbsp;状态:
							<s:select list="#{1:'有效',0:'失效'}"  headerKey="" headerValue="-所有-"
								id="search_drl_states" theme="simple" cssClass="clearable" name="states"></s:select>
					</td>
					<td class="mtd">
							&nbsp;
							<input type="button" id="searchButton"
							class="o-btn SubmitButton" value="搜 索" onclick='goToPage(1)'/>
					</td>
				</tr>
				<tr>
					<td colspan="2">
						<span id="lbl_list_count">共搜索到 <b>${count}</b> 条符合条件的记录。</span>
						<input type="button" id="addGoodButton"
							class="o-btn SubmitButton" value="新增物品" />
					</td>
				</tr>
			</table>
		</div>
		<div class="PageChild_List">
			<table width="100%" border="0" cellspacing="0"
				style="text-align: left">
				<tbody class="PageChild_List_head">
					<tr>
						<td width="16">
							<input id="Chk_All" type="checkbox" name="Chk_All"
								onclick="checkAll('Chk_Num')" />
						</td>
						<td width="16">
							<img src="themes/images/default/icons/pcde_314.png" width="16"
								height="16" />
						</td>
						<td>
							物品编号
						</td>
						<td>
							物品名称
						</td>
						<td>
							物品数量
						</td>
						<td class="td_width40">
							编辑
						</td>
						<td class="td_width40">
							删除
						</td>
						<td class="td_width40">
							状态
						</td>
					</tr>
				</tbody>
				<tbody class="PageChild_List_main" style="text-align: left">
					<s:if test="goodInfoList != null && goodInfoList.size != 0">
					<s:iterator value="goodInfoList" var="item" status="no">
						<tr class='td_no_bord'>
							<td class="td_width25">
								<span title="24"><input id="Chk_Num" type="checkbox"
										 value="${item.id}" /> </span>
							</td>
							<td class="td_width25">
								<s:property value="#no.count" />
							</td>
							<td>
								<span>${item.goodNo} </span>&nbsp;
							</td>
							<td>
								${item.goodName}&nbsp;
							</td>
							<td>
								${item.goodNum}&nbsp;
							</td>
							<td>
								<a class="ui-link-edit-button" id="sender_${item.id}"
									href="javascript:void(0);" state="0"
									entityId="${item.id}"> <img
										src="themes/icons/edit.png" title="进行编辑" /> </a> &nbsp;
							</td>
							<td>
								<a href="javascript:void(0);" class="ui-link-delete-button"
									entityId="${item.id}" onclick=''><img
										src="themes/icons/delete.png" /> </a>
							</td>
							<td>
								<s:if test="#item.states==0">
									<a href="javascript:void(0);" onclick='location="goodInfo!toEnable.action?goodId=${item.id}"'><img src=" themes/icons/btn_disable.png" /> </a>
								</s:if>
								<s:if test="#item.states==1">
									<a href="javascript:void(0);" onclick='location="goodInfo!toDisable.action?goodId=${item.id}"'><img src=" themes/icons/btn_enable.png" /> </a>
								</s:if>
							</td>
						</tr>
					</s:iterator>
					</s:if><s:else>
						<tr><td colspan="9">无记录</td></tr>
					</s:else>
				</tbody>
			</table>
		</div>
		<!--分页导航开始-->
		<div id="divTopPageNavi" class="list_r_title_text3">
		<input class="hiddenObject" value="${currpage }" id="currentPage">
			<s:if test="currpage<=1">
				<span class='list_r_title_text3a'> <img
						src=" themes/images/default/page_up_gray.gif"></img> </span>

			</s:if>
			<s:else>
				<span class='list_r_title_text3a'> <a name="link_page_prev"
					id="link_page_prev" href="javascript:void(0);"
					currentPage="${currpage-1}"> <img
							src=" themes/images/default/page_up.gif"></img> </a> </span>
			</s:else>
			<span class='list_r_title_text3b'> 第${currpage }页/共${totalpage}页 </span>
			<s:if test="currpage>=totalpage">
				<span class='list_r_title_text3a'> <img
						src=" themes/images/default/page_down_gray.gif"></img> </span>
			</s:if>
			<s:else>
				<span class='list_r_title_text3a'> <a name="link_page_next"
					id="link_page_next" href="javascript:void(0);"
					currentPage="${currpage+1 }"> <img
							src=" themes/images/default/page_down.gif"></img> </a> </span>
			</s:else>
			<span id="goToPageTextArea"><input type="text"
					class="easyui-numberbox" id="goPageNum" max="${totalpage}" min="1" />
				<input type="button" id="turnToPageButton" value="GO" />
			</span>
		</div>
		<!--分页导航结束-->
		<div>
			<input type="button" name="btn_Delete" class="o-btn SubmitButton"
				value="删 除" id="btn_Delete"
				onclick="deleteAll('Chk_Num')">
		</div>
	</body>
	<!-- 弹出层标签 -->
	<div id="dialog-form" style="display: none;" title="新增物品信息">
		<div class="ui-mainTab">
			<form id="form" action="">
			<div><input type="text" id="goodId" class="hiddenObject clearable" />
				<table width="100%" class="tb tb2">
					<tr>
						<td class="mtd">
							&nbsp;物品编码:
						</td>
						<td>
							<input class="control required-field clearable" type="text" id="txt_goodNo">
						</td>
					</tr>
					<tr>
						<td class="mtd">
							&nbsp;物品名称:
						</td>
						<td>
							<input class="control required-field clearable" type="text" id="txt_goodName">
						</td>
					</tr>
					<tr>
						<td class="mtd">
							&nbsp;物品数量(增量):
						</td>
						<td>
							<input class="control required-field clearable" type="text" id="txt_goodNum">
						</td>
					</tr>
					<tr>
						<td>
							&nbsp;
						</td>
						<td>
							<div>
								<input id="btnSubmit" type="button" value="提 交" class="o-btn SubmitButton">
								&nbsp;
								<input type="button" name="name" id="cancelAddGoodsInfoButton"
									class="dialogFormCloseButton o-btn" dialogForm="#dialog-form"
									value="关闭" />
							</div>
						</td>
					</tr>
				</table>
			</div>
			</form>
		</div>
	</div>
</html>